<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateWechatSeries extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {

        Schema::create('user_wechat_oauth', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('uid')->unsigned()->nullable(true)->comment('用户id');
            $table->string('nickname',32)->comment('用户昵称');
            $table->tinyInteger('sex')->default(0)->comment('性别');
            $table->char('openid',28)->nullable(false)->comment('openid');
            $table->char('unionid',28)->nullable(true)->comment('unionid');
            $table->string('language',16)->comment('语言');
            $table->string('country',16)->comment('国家');
            $table->string('province',16)->comment('省份');
            $table->string('city',16)->comment('城市');
            $table->string('headimgurl',255)->comment('用户头像');
            $table->string('groupid',255)->comment('用户分组');
            $table->string('tagid_list',255)->comment('用户被打上的标签ID列表');
            $table->tinyInteger('subscribe')->default(0)->comment('关注状态');
            $table->string('qr_scene',32)->comment('二维码扫码场景');
            $table->string('qr_scene_str',32)->comment('二维码扫码场景描述');
            $table->string('subscribe_scene',32)->comment('关注的渠道来源');
            $table->integer('subscribe_time')->unsigned()->comment('关注时间');
            $table->string('remark',255)->comment('用户备注');
            $table->timestamps();
            $table->softDeletes();
            $table->comment("用户微信授权表");
        });

        Schema::create('user_applite_oauth', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('uid')->unsigned()->nullable(true)->comment('用户id');
            $table->string('nickname',32)->comment('用户昵称');
            $table->tinyInteger('sex')->default(0)->comment('性别');
            $table->char('openid',28)->nullable(false)->comment('openid');
            $table->char('unionid',28)->nullable(true)->comment('unionid');
            $table->string('language',16)->comment('语言');
            $table->string('country',16)->comment('国家');
            $table->string('province',16)->comment('省份');
            $table->string('city',16)->comment('城市');
            $table->string('headimgurl',255)->comment('用户头像');
            $table->string('remark',255)->comment('用户备注');
            $table->timestamps();
            $table->softDeletes();
            $table->comment("用户小程序授权表");
        });

        Schema::create('wechat_reply_keywords', function (Blueprint $table) {
            $table->increments('id');
            $table->string('keywords')->comment('关键字');
            $table->integer('reply_id')->comment('回复id');
            $table->integer('begin_time')->unsigned()->default(0)->comment('开始时间');
            $table->integer('end_time')->unsigned()->default(0)->comment('结束时间');
            $table->softDeletes();
            $table->timestamps();
            $table->comment("微信关键字回复配置表");
        });

        Schema::create('wechat_reply_content', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title',32)->nullable()->comment('场景描述');
            $table->string('type',32)->nullable()->comment('回复类型');
            $table->text('content')->nullable()->comment('回复内容');
            $table->timestamps();
            $table->softDeletes();
            $table->comment("微信回复内容表");
        });

        Schema::create('wechat_channel', function (Blueprint $table) {
            $table->increments('id');
            $table->string('channel_name',32)->comment('渠道名称');
            $table->string('channel_code',32)->nullable()->comment('渠道识别码');
            $table->tinyInteger('channel_type')->default(0)->comment('渠道类型');
            $table->unsignedInteger('reply_id')->default(0)->comment('回复id');
            $table->string('ticket')->nullable()->comment('二维码ticket');
            $table->string('remark')->nullable()->nullable()->comment('备注');
            $table->unsignedInteger('expire_at')->nullable()->comment('过期时间');

            $table->softDeletes();
            $table->timestamps();
            $table->comment("微信渠道");
        });

        Schema::create('wechat_channel_log', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('channel_id')->unsigned()->comment('渠道id');
            $table->char('openid',28)->comment('openid');
            $table->tinyInteger('type')->default(0)->comment('类型，0扫码1关注');
            $table->softDeletes();
            $table->timestamps();
            $table->comment("微信渠道日志表");
        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_wechat_oauth');
        Schema::dropIfExists('user_applite_oauth');
        Schema::dropIfExists('wechat_reply_keywords');
        Schema::dropIfExists('wechat_reply_content');
        Schema::dropIfExists('wechat_channel');
        Schema::dropIfExists('wechat_channel_log');

    }
}
